<?php 
$bg_errorMsg = '';
$bg_success = '';
$action = getValue('action','str','POST','');
if($action == 'execute'){
    $name_field = getValue('name','str','POST','',2);
    $email_field = getValue('email','str','POST','',2);
    if(!filter_var($email_field, FILTER_VALIDATE_EMAIL)){
        $bg_errorMsg .= 'Email không đúng định dạng <br>';
    }
    $title_field = getValue('title','str','POST','',2);
    $content_field = getValue('content','str','POST','',2);
    $con_date = time();
    $myform = new generate_form();
    $myform->add('con_name','name_field',0,1,'',1,'Bạn chưa nhập tên');
    $myform->add('con_email','email_field',0,1,'',1,'Bạn chưa nhập email');
    $myform->add('con_subject','title_field',0,1,'',1,'Bạn chưa nhập tiêu đề');
    $myform->add('con_detail','content_field',0,1,'',1,'Bạn chưa nhập nội dung');
    $myform->add('con_date','con_date',1,1,0);
    $myform->addTable('contact');
    $bg_errorMsg .= $myform->checkdata();
    if($bg_errorMsg == ''){
        $db = new db_execute($myform->generate_insert_SQL());
        $bg_success = 1;
    }
    
}

$db_config = new db_query('SELECT * FROM configuration WHERE con_type = "contact" LIMIT 1');
$configDetail = mysql_fetch_assoc($db_config->result);
$contact_site = json_decode(base64_decode($configDetail['con_value']),true);
unset($db_config);
?>
<div class="main">
    <? include '../includes/inc_promotion_feed.php'?>
    <div class="primary">
        <div class="left_col">
            <div class="contact">
                <div class="contact_detail">
                    <div class="contact_info">
                        <h2>Liên hệ với chúng tôi</h2>  
                        <div>
                            <h3>Địa chỉ: </h3>
                            <p><?=$contact_site['address']?></p>
                        </div>
                        <div><h3>Điện thoại: </h3><p><?=$contact_site['phone']?></p></div>
                        <div><h3>Hotline: </h3><p><?=$contact_site['hotline']?></p></div>
                        <div><h3>Fax: </h3><p><?=$contact_site['fax']?></p></div>
                        <div><h3>Email: </h3><p><?=$contact_site['email']?></p></div>
                        <div><h3>Yahoo: </h3><p><?=$contact_site['yahoo']?></p></div>
                        <div><h3>Skype: </h3><p><?=$contact_site['skype']?></p></div>   
                        
                    </div>  
                    <div class="contact_map">
                    <img width="310" height="310" alt="Bản đồ trung tâm Lời sự sáng" src="<?=FOLDER_TEMPLATE?>/modern/themes/img/map.jpg"/>
                        <!--<img alt="Bản đồ trung tâm" src="http://maps.googleapis.com/maps/api/staticmap?center=<?=$contact_site['address']?>&zoom=14&size=310x310&sensor=false"/>
                        <iframe width="355" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=vi&amp;geocode=&amp;q=24+Ho%C3%A0ng+Nh%C6%B0+Ti%E1%BA%BFp,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=0&amp;oq=24,+Ho%C3%A0ng+Nh%C6%B0&amp;sll=37.0625,-95.677068&amp;sspn=37.325633,86.572266&amp;ie=UTF8&amp;hq=&amp;hnear=Ho%C3%A0ng+Nh%C6%B0+Ti%E1%BA%BFp,+Ho%C3%A0n+Ki%E1%BA%BFm,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;ll=21.044778,105.875183&amp;spn=0.010754,0.021136&amp;t=m&amp;z=14&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=vi&amp;geocode=&amp;q=24+Ho%C3%A0ng+Nh%C6%B0+Ti%E1%BA%BFp,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;aq=0&amp;oq=24,+Ho%C3%A0ng+Nh%C6%B0&amp;sll=37.0625,-95.677068&amp;sspn=37.325633,86.572266&amp;ie=UTF8&amp;hq=&amp;hnear=Ho%C3%A0ng+Nh%C6%B0+Ti%E1%BA%BFp,+Ho%C3%A0n+Ki%E1%BA%BFm,+H%C3%A0+N%E1%BB%99i,+Vi%E1%BB%87t+Nam&amp;ll=21.044778,105.875183&amp;spn=0.010754,0.021136&amp;t=m&amp;z=14" style="color:#0000FF;text-align:left">Xem Bản đồ cỡ lớn hơn</a></small>
                    --></div>  
                </div>
                <div class="contact_form">
                    <h2>Liên hệ theo mẫu</h2>
                    <form class="form" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
                    <?=($bg_errorMsg ? '<div class="alert">'.$bg_errorMsg.'</div>' : '')?>
                    <?=($bg_success ? '<div class="alert alert-success">'.'Cảm ơn bạn đã gửi liên hệ. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!'.'</div>' : '')?>
                        <input type="text" value="" placeholder="Họ tên của bạn" class="inputtxt" name="name"/><br />
                        <input type="text" value="" placeholder="Email của bạn" class="inputtxt" name="email"/><br />
                        <input type="text" value="" placeholder="Tiêu đề liên hệ" class="inputtxt" name="title"/><br />
                        <textarea placeholder="Nội dung liên hệ" class="inputtxt inputtxtArea" name="content"></textarea><br />
                        <input type="submit" class="btn logMeIn" id="btnSend" value="Gửi đi" name="" />  
                        <input type="hidden" name="action" value="execute"/>  
                    </form>
            	</div>
            </div>
        </div><!-- End left_col -->
        <div class="right_col">
            <div class="box_right">
                <h3>Chương trình khuyến mại</h3>
                <div class="box_right_img">
                    <img src="../template/default/themes/img/promotion1.jpg" alt="khuyến mại 1"/>
                </div>
            </div>
            <div class="box_right">
                <h3>Chương trình khuyến mại 2</h3>
                <div class="box_right_img">
                    <img src="../template/default/themes/img/promotion2.jpg" alt="khuyến mại 2"/>
                </div>
            </div>
        </div><!-- End right_col -->
    </div><!-- End primary -->
</div><!-- End main -->